package com.yulongtian.oneProblemEveryDay.month202302;

import java.util.HashMap;

/**
 * https://leetcode.cn/problems/decode-the-message/
 * 可
 *
 * @author yulongTian
 * @create 2023-02-01 8:56
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(decodeMessage(
                "the quick brown fox jumps over the lazy dog",
                "vkbs bs t suepuv"));
    }

    public static String decodeMessage(String key, String message) {
        int[] cnt = new int[26];
        HashMap<Character, Character> map = new HashMap<>();
        for (int i = 0, index = 0; i < key.length(); i++) {
            char c = key.charAt(i);
            if (c != ' ' && cnt[c - 'a'] == 0) {
                map.put(c, (char) (index + 'a'));
                index++;
                cnt[c - 'a']++;
            }
        }
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < message.length(); i++) {
            char c = message.charAt(i);
            if (c == ' ') {
                ans.append(c);
            } else {
                ans.append(map.get(c));
            }
        }
        return ans.toString();
    }

}
